import {
  iosProvinces,
  iosCitys,
  iosCountys
} from "@/components/share/area/areaData_v2.js";

export default function (Vue) {
  //省份
  Vue.filter("province", function (val) {
    var reg = new RegExp("[\\u4E00-\\u9FFF]+", "g");
    if (reg.test(val)) {
      return val;
    }
    if (val && val != null && val != "undefined") {
      for (var i = 0; i < iosProvinces.length; i++) {
        if (iosProvinces[i].id == val) {
          return iosProvinces[i].value;
        }
      }
    }
  });
  //市份
  Vue.filter("city", function (val) {
    var reg = new RegExp("[\\u4E00-\\u9FFF]+", "g");
    if (reg.test(val)) {
      return val;
    }
    if (val && val != null && val != "undefined") {
      for (var i = 0; i < iosCitys.length; i++) {
        if (iosCitys[i].id == val) {
          return iosCitys[i].value;
        }
      }
    }
  });
  //区
  Vue.filter("district", function (val) {
    var reg = new RegExp("[\\u4E00-\\u9FFF]+", "g");
    if (reg.test(val)) {
      return val;
    }
    if (val && val != null && val != "undefined") {
      for (var i = 0; i < iosCountys.length; i++) {
        if (iosCountys[i].id == val) {
          return iosCountys[i].value;
        }
      }
    }
  });
  //省市区反向过滤
  //省份
  Vue.filter("TextProvince", function (val) {
    if (val && val != null && val != "undefined") {
      for (var i = 0; i < iosProvinces.length; i++) {
        if (iosProvinces[i].value == val) {
          return iosProvinces[i].id;
        }
      }
    }
  });
  //市份
  Vue.filter("TextCity", function (val) {
    if (val && val != null && val != "undefined") {
      for (var i = 0; i < iosCitys.length; i++) {
        if (iosCitys[i].value == val) {
          return iosCitys[i].id;
        }
      }
    }
  });
  //区
  Vue.filter("TextDistrict", function (val) {
    if (val && val != null && val != "undefined") {
      for (var i = 0; i < iosCountys.length; i++) {
        if (iosCountys[i].value == val) {
          return iosCountys[i].id;
        }
      }
    }
  });
  Vue.filter("PoState", (val) => {
    if (!val) {
      return "";
    }
    switch (val) {
      case "11":
        return "初始";
        break;
      case "12":
        return "提交";
        break;
      case "20":
        return "订单受理";
        break;
      case "21":
        return "物流集单中";
        break;
      case "22":
        return "物流派单中";
        break;
      case "23":
        return "物流派单确认";
        break;
      case "29":
        return "物流派单撤单";
        break;
      case "30":
        return "仓库入库交接";
        break;
      case "31":
        return "订单受理";
        break;
      case "32":
        return "仓储派单拒单";
        break;
      case "39":
        return "仓库出库交接";
        break;
      case "41":
        return "配送派单受理";
        break;
      case "42":
        return "排车";
        break;
      case "43":
        return "提货中";
        break;
      case "44":
        return "已排车";
        break;
      case "49":
        return "配送派单拒单";
        break;
      case "51":
        return "司机已受理";
        break;
      case "52":
        return "提货交接";
        break;
      case "53":
        return "物流中转交接";
        break;
      case "55":
        return "集货交接";
        break;
      case "59":
        return "司机拒单";
        break;
      case "56":
        return "送货交接";
        break;
      case "81":
        return "到货签收";
        break;
      case "R34":
        return "物流出库结束";
        break;
      case "W30":
        return "设备绑定";
        break;
    }
  });
  //图片url转换
  Vue.filter("fileImg", function (val) {
    let vals = val.replace(/\\/g, "/");
    return process.env.Upload_Files + vals;
  });

  Vue.filter("filterImg", function (val) {
    if (val != null && val != "null") {
      if (
        val[0] != null &&
        val != "null" &&
        JSON.parse(val)[0] != null &&
        JSON.parse(val)[0] != "null" &&
        JSON.parse(val)[0].Mobile
      ) {
        return JSON.parse(val)[0].Mobile.Url + JSON.parse(val)[0].Mobile.Name;
      } else {
        return "/static/img/none.jpg";
      }
    } else {
      return "/static/img/none.jpg";
    }
  });

  // 时间轴
  Vue.filter("timeshort", function (value) {
    var time = value ? value.replace("T", " ") : "";
    return time.substr(0, (time.length - 3))
    // .substr(0,(time.length-8));
  });
  Vue.filter("timeReplaceT", function (value) {
    var time = value ? value.replace("T", " ") : "";
    return time;
  })
  Vue.filter("leavetype", function (val) {

    switch (val) {
      case "1":
        return '年假';
        break;
      case "2":
        return '事假';
        break;
      case "3":
        return '病假';
        break;
      case "4":
        return '调休假';
        break;
      case "5":
        return '产假/陪产假';
        break;
      case "6":
        return '婚假';
        break;
      case "7":
        return '丧假';
        break;
    }
  });
  Vue.filter('removeSplash', function (val) {
    if (val && val.indexOf('/') > -1) {
      let arr = val.split('/');
      if (arr.length > 1) {
        var x = new Set(arr);
        return [...x].join('');
      } else {
        return val.split('/').join('');
      }
    } else {
      return val;
    }
  });
  Vue.filter('GetDate', function (val) {
    if (val && val.indexOf('T') > -1) {
      return val.split('T')[0];
    } else {
      return val;
    }
  });
  Vue.filter("filterImgUrl", function (val) {
    if (val != null && val != "null" && val && val != '[]' && val != '[null,null,null,null]') {
      val = JSON.parse(val);
      if (val.length == 1 && !val[0].Mobile) {
        return "https://image.csyaoly.com" + val;
      } else {
        if (!val[0].Mobile) {
          return val[0];
        } else {
          return val[0].Mobile.Url + val[0].Mobile.Name;
        }
      };
    } else {
      return "/static/img/none.jpg";
    }
  });
  Vue.filter("simpleImgUrl", function (val) {
    if (val != null && val != "null" && val) {
      return "https://image.csyaoly.com" + val;
    }
  });
}
